/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upf.grupof.projectphotos.messagesys;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.filetransfer.FileTransferRequest;
import org.jivesoftware.smackx.filetransfer.IncomingFileTransfer;

/**
 *
 * @author fredi
 */
public class ThreadR extends Thread{
    
    private InstantMessage im;
    private FileTransferRequest ftr;
    private String path;
    
    public ThreadR(InstantMessage im, FileTransferRequest ftr, String path){
        this.im=im;
        this.ftr=ftr;
        this.path=path;
    }
    
    public void run(){
        IncomingFileTransfer trf = ftr.accept();
        int progress = 0;
        
        File file= new File("C:\\fotosRecibidas");
        if(!file.exists()){
            file.mkdirs();
        }
        try {
            trf.recieveFile(new File(file+"\\"+ftr.getDescription()));
        } catch (XMPPException ex) {
            Logger.getLogger(ThreadR.class.getName()).log(Level.SEVERE, null, ex);
        }
        while(!trf.isDone()) {
            progress = (int)(trf.getProgress()*100);
            System.out.println(progress);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadR.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
